25 #define foreach(x, v) for (typeof (v).begin() x=(v).begin(); x !=(v).end(); ++x)
26 #define For(i, a, b) for (int i=(a); i<(b); ++i)
27 #define D(x) cout << #x " is " << x << endl
32 point(){} point(int x
, int y
) : x(x
), y(y
) {}
33 bool operator < (const point
&t
) const {
34 return x
* t
.y
- y
* t
.x
> 0;
36 bool operator == (const point
&t
) const {
37 return x
* t
.y
- y
* t
.x
== 0;
39 bool operator <= (const point
&t
) const {
40 return *this < t
or *this == t
;
42 bool operator != (const point
&t
) const {
47 typedef pair
< point
, point
> interval
;
49 // Returns true if interval 'a' is strictly included in interval 'b'
50 bool included(const interval
&a
, const interval
&b
) {
51 return b
.first
< a
.first
and a
.second
< b
.second
;
54 const int MAXN
= 1001;
56 interval intervals
[MAXN
];
59 void delete_redundant() {
61 for (int i
= 0; i
< B
; ++i
) {
62 for (int j
= 0; j
< B
; ++j
) {
63 // delete interval i if interval j is completely inside it
64 if (included(intervals
[j
], intervals
[i
])) {
71 for (int i
= 0; i
< B
; ++i
) {
73 intervals
[k
++] = intervals
[i
];
82 for (int i
= 0; i
< B
; ++i
) {
84 cin
>> p1
.x
>> p1
.y
>> p2
.x
>> p2
.y
;
86 if (p2
< p1
) swap(p1
, p2
);
87 intervals
[i
] = make_pair( p1
, p2
);
89 //printf("Before removing redundant B is %d\n", B);
91 sort(intervals
, intervals
+ B
);
92 //printf("After removing redundant B is %d\n", B);
94 //printf("Before removing duplicates B is %d\n", B);
95 B
= unique(intervals
, intervals
+ B
) - intervals
;
96 //printf("After removing duplicates B is %d\n", B);
101 point pick
= intervals
[i
].second
;
102 while (i
< B
and intervals
[i
].first
<= pick
) i
++;